package com.ruoyi.report_jl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_jl.domain.bo.ReportJlXjlljxjlbBsInfoBo;
import com.ruoyi.report_jl.domain.vo.ReportJlXjlljxjlbBsInfoVo;
import com.ruoyi.report_jl.domain.ReportJlXjlljxjlbBsInfo;
import com.ruoyi.report_jl.mapper.ReportJlXjlljxjlbBsInfoMapper;
import com.ruoyi.report_jl.service.IReportJlXjlljxjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 细集料棱角性试验检测记录（间隙率法）Service业务层处理
 *
 * @author tll
 * @date 2024-07-31
 */
@RequiredArgsConstructor
@Service
public class ReportJlXjlljxjlbBsInfoServiceImpl implements IReportJlXjlljxjlbBsInfoService {

    private final ReportJlXjlljxjlbBsInfoMapper baseMapper;

    /**
     * 查询细集料棱角性试验检测记录（间隙率法）
     */
    @Override
    @FIllBasicInfo
    public ReportJlXjlljxjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询细集料棱角性试验检测记录（间隙率法）列表
     */
    @Override
    public TableDataInfo<ReportJlXjlljxjlbBsInfoVo> queryPageList(ReportJlXjlljxjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportJlXjlljxjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportJlXjlljxjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询细集料棱角性试验检测记录（间隙率法）列表
     */
    @Override
    public List<ReportJlXjlljxjlbBsInfoVo> queryList(ReportJlXjlljxjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportJlXjlljxjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportJlXjlljxjlbBsInfo> buildQueryWrapper(ReportJlXjlljxjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportJlXjlljxjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportJlXjlljxjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportJlXjlljxjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportJlXjlljxjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportJlXjlljxjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportJlXjlljxjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportJlXjlljxjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportJlXjlljxjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportJlXjlljxjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportJlXjlljxjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportJlXjlljxjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportJlXjlljxjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportJlXjlljxjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportJlXjlljxjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportJlXjlljxjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportJlXjlljxjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportJlXjlljxjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportJlXjlljxjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportJlXjlljxjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportJlXjlljxjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportJlXjlljxjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportJlXjlljxjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportJlXjlljxjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportJlXjlljxjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportJlXjlljxjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportJlXjlljxjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportJlXjlljxjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportJlXjlljxjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getSycs1()), ReportJlXjlljxjlbBsInfo::getSycs1, bo.getSycs1());
        lqw.eq(bo.getSyzlm01() != null, ReportJlXjlljxjlbBsInfo::getSyzlm01, bo.getSyzlm01());
        lqw.eq(bo.getSyzlm11() != null, ReportJlXjlljxjlbBsInfo::getSyzlm11, bo.getSyzlm11());
        lqw.eq(bo.getSyzlm21() != null, ReportJlXjlljxjlbBsInfo::getSyzlm21, bo.getSyzlm21());
        lqw.eq(bo.getSytj1() != null, ReportJlXjlljxjlbBsInfo::getSytj1, bo.getSytj1());
        lqw.eq(bo.getSymdf1() != null, ReportJlXjlljxjlbBsInfo::getSymdf1, bo.getSymdf1());
        lqw.eq(StringUtils.isNotBlank(bo.getSycs2()), ReportJlXjlljxjlbBsInfo::getSycs2, bo.getSycs2());
        lqw.eq(bo.getSyzlm02() != null, ReportJlXjlljxjlbBsInfo::getSyzlm02, bo.getSyzlm02());
        lqw.eq(bo.getSyzlm12() != null, ReportJlXjlljxjlbBsInfo::getSyzlm12, bo.getSyzlm12());
        lqw.eq(bo.getSyzlm22() != null, ReportJlXjlljxjlbBsInfo::getSyzlm22, bo.getSyzlm22());
        lqw.eq(bo.getSytj2() != null, ReportJlXjlljxjlbBsInfo::getSytj2, bo.getSytj2());
        lqw.eq(bo.getSymdf2() != null, ReportJlXjlljxjlbBsInfo::getSymdf2, bo.getSymdf2());
        lqw.eq(StringUtils.isNotBlank(bo.getSycs3()), ReportJlXjlljxjlbBsInfo::getSycs3, bo.getSycs3());
        lqw.eq(bo.getSyzlm03() != null, ReportJlXjlljxjlbBsInfo::getSyzlm03, bo.getSyzlm03());
        lqw.eq(bo.getSyzlm13() != null, ReportJlXjlljxjlbBsInfo::getSyzlm13, bo.getSyzlm13());
        lqw.eq(bo.getSyzlm23() != null, ReportJlXjlljxjlbBsInfo::getSyzlm23, bo.getSyzlm23());
        lqw.eq(bo.getSytj3() != null, ReportJlXjlljxjlbBsInfo::getSytj3, bo.getSytj3());
        lqw.eq(bo.getSymdf3() != null, ReportJlXjlljxjlbBsInfo::getSymdf3, bo.getSymdf3());
        lqw.eq(bo.getSypjz() != null, ReportJlXjlljxjlbBsInfo::getSypjz, bo.getSypjz());
        return lqw;
    }

    /**
     * 新增细集料棱角性试验检测记录（间隙率法）
     */
    @Override
    public Boolean insertByBo(ReportJlXjlljxjlbBsInfoBo bo) {
        ReportJlXjlljxjlbBsInfo add = BeanUtil.toBean(bo, ReportJlXjlljxjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改细集料棱角性试验检测记录（间隙率法）
     */
    @Override
    public Boolean updateByBo(ReportJlXjlljxjlbBsInfoBo bo) {
        ReportJlXjlljxjlbBsInfo update = BeanUtil.toBean(bo, ReportJlXjlljxjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportJlXjlljxjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除细集料棱角性试验检测记录（间隙率法）
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
